/*
 * @(#) SsmSqlDaoImpl .java  1.0  2004-4-12
 *
 * Copyright 2003 by LongTop Corporation.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * LongTop Corporation ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with LongTop.
 */
package com.cnc.ssm.dao;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.cnc.ssm.UserInfo;

/**
 * User: Du bf Date: 2005-3-29
 */
public class SsmSqlDaoImpl extends SqlMapClientDaoSupport implements ISsmSqlDao {

	public UserInfo getUserInfo(String userName) throws DataAccessException {
		return (UserInfo) getSqlMapClientTemplate().queryForObject(
				"getUserInfo", userName);
	}

	public List getFuncPermission(String userCode) throws DataAccessException {
		if (userCode.equalsIgnoreCase("admin"))
			return (List) getSqlMapClientTemplate().queryForList(
					"getFunction", null);
		return (List) getSqlMapClientTemplate().queryForList(
				"getFuncPermission", userCode);
	}

	public List getAuthInfo(String refType, String refCode)
			throws DataAccessException {
		HashMap hm = new HashMap();
		hm.put("refType", refType);
		hm.put("refCode", refCode);
		return (List) getSqlMapClientTemplate()
				.queryForList("getAuthInfo", hm);
	}

	public int deleteMenuAuth(String refType, String refCode)
			throws DataAccessException {
		HashMap paramList = new HashMap();
		paramList.put("refType", refType);
		paramList.put("refCode", refCode);
		return (getSqlMapClientTemplate().update("deleteMenuAuth", paramList));
	}

	public int deleteRole(String roleCode) throws DataAccessException {
		return (getSqlMapClientTemplate().update("deleteRole", roleCode));
	}

	public int deleteOper(String operCode) throws DataAccessException {
		return (getSqlMapClientTemplate().update("deleteOper", operCode));
	}

	//
	public List listUserMenu(String userCode, String i18n)
			throws DataAccessException {
		if (userCode.equalsIgnoreCase("admin"))
			return (List) getSqlMapClientTemplate().queryForList("listMenu",null);
		return (List) getSqlMapClientTemplate().queryForList("listUserMenu_" + i18n, userCode);
	}

	public int deleteFunctionAuth(String refType, String refCode)
			throws DataAccessException {
		HashMap paramList = new HashMap();
		paramList.put("refType", refType);
		paramList.put("refCode", refCode);
		return (getSqlMapClientTemplate().update("deleteFunctionAuth",
				paramList));
	}

	public List listOper(String roleCode) {
		return (List) getSqlMapClientTemplate().queryForList("listOper",
				roleCode);
	}

	public List listOper(HashMap hs) {
		return (List) getSqlMapClientTemplate().queryForList("listOperator",
				hs);
	}

	public List listRole(HashMap hs) {
		return (List) getSqlMapClientTemplate().queryForList("listRole2", hs);
	}

	public List listRole(String operCode) {
		return (List) getSqlMapClientTemplate().queryForList("listRole",
				operCode);
	}

	public boolean existUser(String userCode) {
		List list = (List) getSqlMapClientTemplate().queryForList(
				"listExistUser", userCode.toUpperCase());
		return (list.iterator().hasNext());
	}

	public boolean existRole(String userRole) {
		List list = (List) getSqlMapClientTemplate().queryForList(
				"listExistRole", userRole.toUpperCase());
		return (list.iterator().hasNext());
	}

	public List listCodeInfo(String codeType) {
		return (List) getSqlMapClientTemplate().queryForList("listCodeInfo",
				codeType);
	}

	public String getNameByCode(String codeType, String codeValue) {
		HashMap hm = new HashMap();
		hm.put("codeType", codeType);
		hm.put("codeValue", codeValue);
		List list = getSqlMapClientTemplate().queryForList("listNameByCode",
				hm);
		Iterator it = list.iterator();
		String name = "";
		if (it.hasNext()) {
			HashMap hm2 = (HashMap) it.next();
			name = String.valueOf(hm2.get("NAME"));
		}
		return (name == null ? "" : name);
	}

	public void updateLoginInfo(Long loginId) {
		getSqlMapClientTemplate().update("updateLoginInfo", loginId);
	}

	public List listCodeType() {
		return getSqlMapClientTemplate().queryForList("listCodeType", "");
	}

	public List listInstTree() {
		return getSqlMapClientTemplate().queryForList("listInstTree", null);
	}

	public List listMenuTree() {
		return getSqlMapClientTemplate().queryForList("listMenuTree", null);
	}

	public boolean existChildMenu(String menuCode) {
		List list = (List) getSqlMapClientTemplate().queryForList(
				"listExistChildMenu", menuCode.toUpperCase());
		return (list.iterator().hasNext());
	}

	public List listSysParam() {
		return getSqlMapClientTemplate().queryForList("listSysParam", null);
	}

	public boolean existMenu(String menuCode) {
		List list = (List) getSqlMapClientTemplate().queryForList(
				"listExistMenu", menuCode.toUpperCase());
		return (list.iterator().hasNext());
	}

	public List listSuperEmployee(String instCode, String emplType) {
		HashMap hs = new HashMap();
		hs.put("instCode", instCode);
		hs.put("emplType", emplType);
		return this.getSqlMapClientTemplate().queryForList(
				"listSuperEmployee", hs);
	}

	public List listEmployee(HashMap hs) {
		return this.getSqlMapClientTemplate().queryForList("listEmployee", hs);
	}

	public void updateUserName(String emplCode, String emplName) {
		HashMap hs = new HashMap();
		hs.put("emplCode", emplCode);
		hs.put("emplName", emplName);
		getSqlMapClientTemplate().update("updateUserName", hs);
	}

	public boolean existEmployee(String emplCode) {
		List list = (List) this.getSqlMapClientTemplate().queryForList(
				"listExistEmployee", emplCode.toUpperCase());
		return (list.iterator().hasNext());
	}

	public boolean existInst(String officeCode) {
		List list = (List) getSqlMapClientTemplate().queryForList(
				"listExistInst", officeCode.toUpperCase());
		return (list.iterator().hasNext());
	}

	public List listInst(String instCode, String instLevel) {
		HashMap hm = new HashMap();
		hm.put("instCode", instCode);
		hm.put("instLevel", instLevel);
		return getSqlMapClientTemplate().queryForList("listInst", hm);
	}

	public List listLoginLog(HashMap hs) {
		return getSqlMapClientTemplate().queryForList("listLoginLog", hs);
	}

	public List listCodeType(HashMap hs) {
		return getSqlMapClientTemplate().queryForList("listCodeType2", hs);
	}

	public boolean existCodeType(String codeType) {
		List list = (List) (getSqlMapClientTemplate().queryForList(
				"existCodeType", codeType));
		return (list.iterator().hasNext());
	}

	public List listCodeInfo(HashMap hs) {
		return getSqlMapClientTemplate().queryForList("listCodeInfo2", hs);
	}

	public List listTaskDetail(String taskid) throws DataAccessException {
		List list = getSqlMapClientTemplate().queryForList("getTaskDetailList", taskid);		
		return list;
	}

}
